package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;

import java.sql.*;
import java.util.concurrent.atomic.AtomicInteger;

public class LogStrongholdDaoImpl extends TempDao {

    public AtomicInteger getMaxEventId(int activityId, int groupId) {
        String sql = "select max(eventId) as maxId from t_c_stonghold_search_log where activityId = ? and groupId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        AtomicInteger maxId = new AtomicInteger(0);
        try {
            getDb().setConnName(DbNameStrategy.getCross2Db());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, activityId);
            call.setInt(i++, groupId);
            rs = call.executeQuery();
            while (rs.next()) {
                maxId = new AtomicInteger(rs.getInt("maxId"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

}
